added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / VBCreateMiniDump / VBApplicationToCrash / MainModule.vb
blob8dd3dc56fd910622cd5aaa2162b2f523bda619ff
1 '*************************** Module Header ******************************'
2 ' Module Name: MainModule.vb
3 ' Project: VBApplicationToCrash
4 ' Copyright (c) Microsoft Corporation.
5 '
6 ' When this application starts, it will launch a Watchdog process. It will also
7 ' create an unhandled exception.
8 '
9 ' This source is subject to the Microsoft Public License.
10 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 ' All other rights reserved.
13 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
14 ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
15 ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
16 '*************************************************************************'
18 Imports System.Runtime.InteropServices
20 Module MainModule
22 Sub Main()
23 Dim demoProcess As Process = Process.GetCurrentProcess()
24 Console.WriteLine("The ID of this Demo Process is " & demoProcess.Id)
26 LaunchWatchdog(demoProcess)
28 ' Wait 2 seconds, so the watch dog process can attach a debugger to this
29 ' application.
30 System.Threading.Thread.Sleep(2000)
32 Console.WriteLine("Press ENTER to throw an unhandled exception...")
33 Console.ReadLine()
35 Try
36 Dim zero As Integer = 0
38 ' This exception will be handled by the catch block, so the watch dog
39 ' will not create a minidump at this moment.
40 Console.WriteLine(1 \ zero)
42 Catch ex As Exception
44 Console.WriteLine(ex.GetType())
46 ' Rethrowing the exception will cause an unhandled exception, and the watch
47 ' dog will create a minidump now.
48 Throw
50 End Try
51 End Sub
53 ''' <summary>
54 ''' Launch the Watchdog process.
55 ''' </summary>
56 ''' <param name="demoProcess"></param>
57 Sub LaunchWatchdog(ByVal demoProcess As Process)
58 Try
59 Console.WriteLine("Launch Watchdog process...")
60 Dim start As ProcessStartInfo = New ProcessStartInfo With _
61 {.Arguments = demoProcess.Id.ToString(),
62 .FileName = "VBCreateMiniDump.exe"}
63 Dim miniDumpCreatorProcess As Process = Process.Start(start)
64 Console.WriteLine("The Watchdog process was launched!")
65 Catch ex As Exception
66 Console.WriteLine("The Watchdog process was not launched!")
67 Console.WriteLine(ex.Message)
68 End Try
69 End Sub
71 End Module